package com.hzcx.app.simplechat.ui.setting.presenter;

import android.app.Activity;
import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.bean.UpLoadImgBean;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.model.SettingModel;
import com.hzcx.app.simplechat.model.UserModel;
import com.hzcx.app.simplechat.ui.setting.bean.AutoSendMessageBean;
import com.hzcx.app.simplechat.ui.setting.contract.AddAutoSendMsgContract;
import com.hzcx.app.simplechat.ui.setting.contract.SettingAutoSendMsgContract;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

public class SettingAutoSendMsgPresenter extends BasePresenter<SettingAutoSendMsgContract.View> implements SettingAutoSendMsgContract.Presenter {

    /**
     * 获取自动回复列表
     *
     * @param context
     * @param isShow
     */
    @Override
    public void getMessageSettingList(Context context, boolean isShow) {
        SettingModel.getAutoSendMessageList(context, new BaseDialogObserver<List<AutoSendMessageBean>>(context, isShow) {
            @Override
            protected void onSuccess(List<AutoSendMessageBean> data) {
                mView.messageResult(data);
            }
        });
    }

    /**
     * 修改某一条消息是否自动回复
     *
     * @param context
     * @param id
     * @param pos
     */
    @Override
    public void updateMessageItemSetting(Context context, int id, int pos) {
        SettingModel.updateAutoSendMsgItem(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.updateItemSuccess(pos);
            }
        });
    }

    /**
     * 删除头条自动打招呼消息
     *
     * @param context
     * @param id
     * @param pos
     */
    @Override
    public void deleteMessageSettingItem(Context context, int id, int pos) {
        SettingModel.deleteAutoSendMessageItem(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.deleteSuccess(pos);
            }
        });
    }

    /**
     * 自动打招呼排序
     *
     * @param context
     * @param data
     */
    @Override
    public void moveMessageSetting(Context context, List<AutoSendMessageBean> data) {
        String id = "";
        for (int i = 0; i < data.size(); i++) {
            if (i == data.size() - 1) {
                id = id + data.get(i).getHost_id();
            } else {
                id = id + data.get(i).getHost_id() + ",";
            }
        }
        SettingModel.moveAutoSendMessage(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.moveSuccess();
            }
        });
    }

    /**
     * 修改自动打招呼设置
     *
     * @param context
     * @param is_hosting
     */
    @Override
    public void updateAutoChat(Context context, String is_hosting) {
        SettingModel.setPrivateConfig(context, null, null, null, is_hosting,null, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.updateAutoSuccess();
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
                mView.updateAutoFail();
            }
        });
    }
}
